//package com.badger.spring.cloud.alibaba.consumer;
//
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.boot.SpringApplication;
//import org.springframework.boot.autoconfigure.SpringBootApplication;
//import org.springframework.cloud.client.ServiceInstance;
//import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
//import org.springframework.cloud.client.loadbalancer.LoadBalancerClient;
//import org.springframework.context.annotation.Bean;
//import org.springframework.web.bind.annotation.GetMapping;
//import org.springframework.web.bind.annotation.RestController;
//import org.springframework.web.client.RestTemplate;
//
///**
// * @EnableDiscoveryClient 开启服务注册和发现
// */
//@SpringBootApplication
//@EnableDiscoveryClient
//public class RibbonConsumerApplication {
//
//    public static void main(String[] args) throws Exception {
//        SpringApplication.run(RibbonConsumerApplication.class, args);
//    }
//
//    @Bean
//    public RestTemplate restTemplate() {
//        return new RestTemplate();
//    }
//
//    @RestController
//    public class DemoController {
//
//        @Autowired
//        private LoadBalancerClient loadBalancerClient;
//        @Autowired
//        private RestTemplate restTemplate;
//
//        private static final String SERVER_NAME = "badger-spring-cloud-alibaba-provider";
//
//        @GetMapping("/ribbon/demo")
//        public String demo() {
//            // 使用 LoadBalanceClient 和 RestTemplate 结合的方式来访问
//            ServiceInstance serviceInstance = loadBalancerClient.choose(SERVER_NAME);
//            String url = String.format("http://%s:%s/%s", serviceInstance.getHost(), serviceInstance.getPort(), "demo");
//            System.out.println("request url:" + url);
//            return restTemplate.getForObject(url, String.class);
//        }
//    }
//}
